package top.aiprogram.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import top.aiprogram.user.entity.Student;
import top.aiprogram.user.service.StudentService;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * Created by Evans on 2017/6/14.
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/test")
    @ResponseBody
    public String testUser(@RequestBody Student student){


        studentService.createStudent(student);
        return "user";
    }

    @RequestMapping("/demo")
    public String testDemo(){

        return "demo";
    }

    @RequestMapping("/upload")
    public String upLoad(MultipartFile file, HttpServletRequest request) throws IOException {

        String name = file.getOriginalFilename();
        File uploadFile = new File("/"+name);
        file.transferTo(uploadFile);
        return "demo";
    }
}
